package com.xc.hotelmgr.order.modules.ctrip.controller;

import com.xc.hotelmgr.order.common.utils.Constant;
import com.xc.hotelmgr.order.common.utils.R;
import com.xc.hotelmgr.order.modules.ctrip.to.payconfir.response.PayConfirResponse;
import com.xc.hotelmgr.order.modules.order.entity.OrderEntity;
import com.xc.hotelmgr.order.modules.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("ctrip/order")
public class CtripCallBack {
    @Autowired
    private OrderService orderService;

    @RequestMapping(value = "payconfir",method = {RequestMethod.GET,RequestMethod.POST})
    public PayConfirResponse getPayConfir(@RequestParam Map<String,Object> params){
        Long buyOrdId = Long.parseLong(params.get("order_id").toString());
        OrderEntity orderEntity =  orderService.sqlSelectByBuyOrdId(buyOrdId, Constant.Channel.Ctrip.getValue());
        PayConfirResponse payConfirResponse = new PayConfirResponse();
        payConfirResponse.setPay_amount(orderEntity.getBuyOrderPrice());
        return payConfirResponse;
    }

    public R test(){
        return R.ok();
    }
}
